package com.xinqing.test.collection.list;

import com.xinqing.test.modle.Age;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * @Author:CHQ
 * @Date:2020/12/29 10:37
 * @Description
 */
public class ListCompare {
    public static void main(String args[]){

        List<Age> ages = new ArrayList<>();
        Age age = new Age("2");
        Age age2 = new Age("7");
        Age age3 = new Age("4");

        ages.add(age);
        ages.add(age2);
        ages.add(age3);

        for (Age x : ages) {
            System.out.println(x.getAge());
        }


        ages.sort(Comparator.comparing(Age::getAge));

        for (Age x : ages) {
            System.out.println(x.getAge());
        }

    }
}
